﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.DynamicData;
using Telerik.Web.UI;

namespace FlexiCommerce.Web.Admin.FlexiAdmin.DynamicData.FieldTemplates
{
    public partial class Categories : FieldTemplateUserControl
    {
        protected override void OnInit(EventArgs e)
        {

            base.OnInit(e);
            MetaTable table = MetaModel.Default.GetTable(typeof(Components.Category));
            DomainDataSourceCategories.SetTable(table);
        }

        protected void RadTreeViewCategories_DataBound(object sender, EventArgs e)
        {
            IList<Components.Category> categories = FieldValue as IList<Components.Category>;
            foreach (Components.Category category in categories)
            {
                RadTreeNode node = RadTreeViewCategories.FindNodeByValue(category.ID.ToString());
                if (node != null)
                {
                    node.Selected = true;
                    node.ExpandParentNodes();
                }
            }
        }
    }
}